#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<queue>
#include<iostream>
using namespace std;


  struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode() : val(0), left(nullptr), right(nullptr) {}
      TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
      TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
  };
 
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root)
    {
        queue<TreeNode*> q;
        queue<int> levelq;
        vector<vector<int>> vv;
        if (root)
        {
            q.push(root);
            levelq.push(0);
        }
        while (!q.empty())
        {
            TreeNode* qfront = q.front();
            int Lfront = levelq.front();

            q.pop();
            levelq.pop();

            if (vv.size() == Lfront)
            {
                vv.push_back(vector<int>());
            }

            vv[Lfront].push_back(qfront->val);

            if (qfront->left)
            {
                q.push(qfront->left);
                levelq.push(Lfront + 1);
            }
            if (qfront->right)
            {
                q.push(qfront->right);
                levelq.push(Lfront + 1);
            }
        }
        cout << vv.size();
        return vv;

    }
};